package it.terry.alarm;



import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class AlarmActivity extends Activity {
	private Context ctx;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		ctx = this.getApplicationContext();
		Handler handler = new MyHandler();
		Intent intent = new Intent(this, MyBroadcastReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
		AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
		
		new AutoAlarmSender(ctx,alarmManager,pendingIntent,handler).start();
		
	}
	 private class MyHandler extends Handler {
		    @Override
		    public void handleMessage(Message msg) {
		      Bundle bundle = msg.getData();
		      if(bundle.containsKey("refresh")) {
		        String value = bundle.getString("refresh");
		        Toast.makeText(ctx,	value, Toast.LENGTH_LONG).show();
		      }
		    }
		  }
	
		
	}


			